package org.example.seat_management.Service.Impl;

import org.example.seat_management.Entity.Classroom;
import org.example.seat_management.Mapper.ClassroomMapper;
import org.example.seat_management.Service.ClassroomService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class ClassroomServiceImpl implements ClassroomService {

    private final ClassroomMapper classroomMapper;

    public ClassroomServiceImpl(ClassroomMapper classroomMapper) {
        this.classroomMapper = classroomMapper;
    }

    @Override
    @Transactional
    public Long create(Classroom classroom) {
        classroomMapper.insert(classroom);
        return classroom.getId();
    }

    @Override
    @Transactional
    public void update(Classroom classroom) {
        classroomMapper.update(classroom);
    }

    @Override
    public Classroom getById(Long id) {
        return classroomMapper.findById(id);
    }

    @Override
    public Classroom getByCode(String roomCode) {
        return classroomMapper.findByCode(roomCode);
    }

    @Override
    public List<Classroom> listAll() {
        return classroomMapper.findAll();
    }
}


